<?php // This pages handles file downloads through headers.

 if (isset($_GET['f_id'])) {
	$f_id = (int) $_GET['f_id'];
} else {
	$f_id = 0;
}

if ($f_id > 0) {
	require('dbconnect.php');
	
	$query = "SELECT file_name, file_type, file_size FROM uploads WHERE upload_id=$f_id";
	$result = mysql_query($query);
	list($fn, $ft, $fs) = mysql_fetch_array($result, MYSQL_NUM);
	
	mysql_close();
	$fn=iconv('UTF-8', 'GBK', $fn);
	$the_file = './uploads/' . $f_id . '-' . $fn;
	
	if (file_exists($the_file)) {

		header ("Content-Type: $ft\n");
		header ("Content-disposition: attachment; filename=\"$fn\"\n");
		header ("content-Length: $fs\n");
		readfile ($the_file);
		
	} else {
		$page_title = 'File Download';
		echo '<p><font color="red">The file could not be located on the server. We apologize for any inconvenience.</font></p>';
	}
} else {
	$page_title='File Download';
	echo '<p><font color="red">Please select a valid file to download.</font></p>';
	
}

?>

